package com.aaa.service.impl;

import com.aaa.dao.CarDao;
import com.aaa.dto.CarDto;
import com.aaa.pojo.DefaultMsg;
import com.aaa.service.CarService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CarServiceImpl extends ServiceImpl<CarDao, CarDto> implements CarService {

    @Resource
    private CarDao carDao;

    @Override
    public List<CarDto> listAllById(Integer userId) {
        return carDao.listAllById(userId);
    }

    @Override
    public DefaultMsg carInsert(Integer userId, Integer goodsId, Integer buyCount) {
        DefaultMsg defaultMsg = new DefaultMsg(200, 1, null, null);
        int i = carDao.carInsert(userId, goodsId, buyCount);
        if (i == 0) defaultMsg.setMsg(0);
        return defaultMsg;
    }

    @Override
    public DefaultMsg deleteCarByCarId(Integer carId) {
        DefaultMsg defaultMsg = new DefaultMsg(200, 1, null, null);
        int i = carDao.deleteCarByCarId(carId);
        if (i == 0) defaultMsg.setMsg(0);

        return defaultMsg;
    }

    @Override
    public DefaultMsg updateCountByGoodsId(Integer goodsId, Integer buyCount) {
        DefaultMsg defaultMsg = new DefaultMsg(200, 1, null, null);
        int i = carDao.updateCountByGoodsId(goodsId,buyCount);
        if (i == 0) defaultMsg.setMsg(0);

        return defaultMsg;
    }
}
